fix(public): fix self-view tracking logic in profile and card view handlers#294
Conversation
|
Hi, |
c3ea871 to
2afa258
Compare
|
@ShantKhatri Done, reverted all unintended formatting changes. Only the isSelfView logic remains. |
ShantKhatri
left a comment
There was a problem hiding this comment.
LGTM! @Harxhit, you can have the final review.
|
Please resolve the merge conflicts and pin me our pr-review channel. |
Signed-off-by: hariom888 <hariom880088@gmail.com>
|
@hariom888 is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
CI — All Checks PassedBackend — PASS
Mobile — SKIP
Web — SKIP
Last updated: |
|
Congratulations @hariom888 on getting PR #294 merged! Thank you for your contribution to the project. To receive the appropriate GSSoC labels and recognition, please mention @Harxhit in the #get-labels channel on our Discord server and share your merged PR link. |
Problem
In apps/backend/src/routes/public.ts, when an authenticated owner views their own profile, viewerId was left as null (not set to their id). The guard
if (viewerId !== user.id)then evaluatesnull !== user.idwhich is always true, so the self-view wasrecorded in cardView anyway. This silently inflated totalViews and uniqueViewers on the analytics dashboard.
Fix
Introduced an explicit
isSelfViewboolean flag in both the /:username and /:username/card/:cardId handlers. When the decoded JWT id matches user.id, isSelfView is set to true and viewerId stays null. The guard is changed fromviewerId !== user.idto!isSelfView, which correctly blocks the insert for authenticated owners while still tracking unauthenticated views with viewerId: null.Affected handlers
Testing
Closes #203